import { createStore } from 'vuex'
import createPersistedState from 'vuex-persistedstate'
import mapControler from "@/components/mapContainer/mapControler";
export default createStore({
  state: {
    mainActvie: 0,
    subActvie: 0,
    datavColors: ['rgb(46, 96, 153)', 'rgb(124, 231, 253)'],
    dataSources:[],
    area:[],
    theme: 0,
    expires_time: sessionStorage.getItem('expires_time') || null,//token过期时间
    ACCESS_TOKEN: sessionStorage.getItem('access_token') || null,
    REFRESH_TOKEN: sessionStorage.getItem('refresh_token') || null,
    mapTypes:[{label:'地图',value:'0'},{label:'卫星',value:'1'},{label:'卫星混合',value:'2'},{label:'地形',value:'3'},{label:'地形混合',value:'4'}],
    mapType:'2',
    coverageData:{
      boundary:{
        color:'#0063f9',
        weight:2,
        id:'',
      }
    }
  },
  getters: {
  },
  mutations: {
    changeMainActive(state, value) {
      state.mainActvie = value
    },
    changeSubActive(state, value) {
      state.subActvie = value
    },
    changeDatavColors(state, value) {
      state.datavColors = value
    },
    changeDataSources(state, value) {
      state.dataSources = value
    },
    changeArea(state, value) {
      state.area = value
    },
    changeTheme(state, value) {
      state.theme = value
    },
    changeExpires_time(state, value) {
      state.expires_time = value
      sessionStorage.setItem('expires_time', value)
    },
    changeACCESS_TOKEN(state, value) {
      state.ACCESS_TOKEN = value
      sessionStorage.setItem('access_token', value)
    },
    changeREFRESH_TOKEN(state, value) {
      state.REFRESH_TOKEN = value
      sessionStorage.setItem('refresh_token', value)
    },
    changeMapType(state, value){
      state.mapType = value
      mapControler.setMapType(value)
    },
    changeBoundary(state, value){
      state.coverageData.boundary = value
    }
  },
  actions: {

  },
  modules: {
  },
  plugins: [
  // 数据持久化
  createPersistedState({
      // 存储方式：localStorage、sessionStorage、cookies
      storage: window.sessionStorage
  })]
})
